<template>
	<view class="page-wrap" :data-theme="theme" :class="theme" :style="globalColor.style">
		<HeadCustom :isAppBtn="false" title="数字职场" :isHome="!isApp"></HeadCustom>
		<view class="fboxRow search-box">
			<view class="input flex1 fboxRow Ycenter font24 color-747986 bg-232732" @click="goPage('search')">
				<text class="bwfont bw-sousuo font24"></text>
				<text class="ml24">搜索职位、公司</text>
			</view>
			<!-- <view class="set-btn ml24 fboxRow Ycenter Xcenter" @click="goPage('user')"><text class="bwfont bw-zhichanggerenguanli1 color-selectedFontColor"></text></view> -->
		</view>
		<!-- banner图 -->
		<view class="banner fboxCol Ycenter" v-if="bannerList.length">
			<swiper
				class="swiper-banner"
				:indicator-dots="true"
				:autoplay="true"
				indicator-color="rgba(0,0,0,0.4)"
				indicator-active-color="#E8CDA7"
				circular
				:current="swiperIndex"
				@change="swiperChange"
			>
				<swiper-item class="pic" v-for="(item, index) in bannerList" :key="index" @click="goBanner(item)">
					<image class="pic" :src="item.bannerImage" mode="aspectFill"></image>
					<!-- <image v-if="index == swiperIndex" class="pic" :src="item.bannerImage + '?' + swiperRandom" :lazy-load="true"></image> -->
					<!-- <image v-if="index == swiperIndex" class="pic" :src="item.bannerImage + '?' + Math.random()" lazy-load></image> -->
				</swiper-item>
			</swiper>
		</view>
		<NavFilter :reqData="reqData" :isFilter="true" @change="tabChange" @login="login" @userVita="userVita" />
		<view class="list">
			<RecruitmentItem v-for="(item, index) in listData" :key="index" :innerData="item" type="recruitmentIndex" />
			<u-loadmore fontSize="24rpx" :status="listConfig.loading" />
		</view>
		<not-login bottom="160rpx" ref="notLogin" :show="!isLogin" />
		<view class="changePage">
			<view class="bottomDetail fboxRow">
				<view class="btn flex1 active zwmsg font30 fboxRow Xcenter Ycenter bg-linear">
					<text class="bwfont bw-zhiwei"></text>
					<text>职位信息</text>
				</view>
				<view class="btn flex1 jlmy font30 fboxRow Xcenter Ycenter" @click="goPage('user')">
					<text class="bwfont bw-wode"></text>
					<text>我的简历</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { resumeInfo, jobFilter, deliverJob, jobCommunicate } from '@/api/recruit.js';
import { getAppBanner } from '@/api/index.js';
import { getRequest } from '@/static/js/common.js';
import { utf8to16, base64decode } from '@/static/js/Base64.js';
import RecruitmentItem from '@/components/card/recruitment-item.vue';
import NavFilter from '../components/nav-filter.vue';
import { listMixins } from '../common/list.mixins.js';
export default {
	mixins: [listMixins],
	components: {
		RecruitmentItem,
		NavFilter
	},
	data() {
		return {
			theme: getApp().globalData.appTheme,
			globalColor: getApp().globalData.globalColor,
			bannerList: [],
			swiperIndex: 0,
			navList: [],
			navIndex: 0,
			listData: [],
			listConfig: {
				loading: 'loading',
				size: 10,
				current: 1,
				total: 0
			},
			reqData: {
				cityId: '',
				educationList: [],
				experienceList: [],
				salaryMax: '',
				salaryMin: '',
				positionType: ''
			},
			isDeliver: false,
			deliverItem: {},
			resumeOpen: false,
			scrollHeight: 374,
			isApp: false,
			isLogin: false,
			isChange: false, // 是否从我的简历跳转过来的，true 点击切换简历时用uniback返回，false uninavg跳转到简历页
			isVitaModal: false,
			vitaType: 'guide' // guide | perfect
		};
	},
	onLoad(option) {
		if (option && option.benwu) {
			const benwu = utf8to16(base64decode(option.benwu));
			const token = {
				access_token: getRequest(benwu, 'token'),
				userId: getRequest(benwu, 'userId'),
				statusBarHeight: getRequest(benwu, 'statusBarHeight')
			};
			getApp().globalData.userId = token.userId;
			getApp().globalData.statusBarHeight = token.statusBarHeight;
			uni.setStorageSync('bw_params', JSON.stringify(token));
		}
		if (option && option.isApp) {
			this.isApp = option.isApp == 1 ? true : false;
		}
		if (option && option.isChange) {
			this.isChange = true
		}
		this.getInfo();
		console.log('数字职场首页 ------ onLoad')
	},
	onShow() {
		const filterTemp = getApp().globalData.filterTemp;
		if (filterTemp.hasOwnProperty('expectCityId')) {
			// this.reqData = filterTemp
			this.reqData.educationList = filterTemp.educationList;
			this.reqData.experienceList = filterTemp.experienceList;
			this.reqData.salaryMin = filterTemp.salary && filterTemp.salary.split('-')[0];
			this.reqData.salaryMax = filterTemp.salary && filterTemp.salary.split('-')[1];
			this.reqData.cityId = filterTemp.expectCityId;
			// this.getInit()
		}
		console.log('数字职场首页 ------ onShow')
	},
	onUnload() {
		console.log('数字职场首页 ------ onUnload')
	},
	methods: {
		// 用户简历情况，第一次进来
		userVita(type){
			this.vitaType = type
			this.isVitaModal = true
		},
		getInfo() {
			// #ifdef H5
				let u = navigator.userAgent;
				const requestSource = /(iPhone|iPad|iPod|iOS)/i.test(u) ? 0 : 1;
				// banner
				getAppBanner({
					bannerPlace: 'APP_JOB_MARKET',
					requestSource: requestSource, // 1 || 2
					showType: 1
				}).then(res => {
					this.bannerList = res.data;
				});
			// #endif
			// #ifdef MP
				// banner
				getAppBanner({
					bannerPlace: 'APP_JOB_MARKET',
					requestSource: 1, // 1 || 2
					showType: 2
				}).then(res => {
					this.bannerList = res.data;
				});
			// #endif
		},
		getInit() {
			this.listConfig.current = 1;
			this.listData = [];
			this.getList();
		},
		tabChange(e) {
			console.log('tabChange', e)
			this.reqData.positionType = e.name == '全部' ? '' : e.name;
			this.getInit();
		},
		getList() {
			jobFilter({ ...this.listConfig, ...this.reqData })
				.then(res => {
					this.listData = this.listData.concat(res.data.list);
					this.listLoading(res);
				})
				.catch(err => {
					if (err.code == 401006) {
						this.getList();
					}
				});
		},
		onReachBottom() {
			this.listMore();
		},
		swiperChange(e) {
			this.swiperIndex = e.detail.current;
		},
		goBanner(item) {
			const { bw_params } = getApp().getBWData(['bw_params']);
			if (bw_params && bw_params.access_token) {
				// if (item.appJumpType == 2) {
				// 	if(item.appJumpPath.includes('/#/')){
				// 		const index = item.appJumpPath.indexOf('/#/')
				// 		// const op =  location.origin + location.pathname +'#' // 'http://ebc-test.benwunet.com/h5/#'
				// 		const url = item.appJumpPath.substring(index+2) // item.appJumpPath.replace(op, '');
				// 		// console.log('url',item.appJumpPath.substring(index+2))
				// 		this.$pageTo(url)
				// 	}else{
				// 		window.open(item.appJumpPath)
				// 	}
				// }else{

				if (this.isApp) {
					const data = {
						type: 'banner',
						...item
					};
					this.$bridge.callHandler('recruitHandler', data, () => {
						console.log('recruitHandler', '返回');
					});
					// 配合安卓临时修改----2023.10.09 15:50
					// let u = navigator.userAgent;
					// if (!/(iPhone|iPad|iPod|iOS)/i.test(u)) {
					// 	if (item.appJumpPath.includes('http')) {
					// 		window.open(item.appJumpPath);
					// 		// const data1 = {
					// 		// 	type: 'hotArticleDetail',
					// 		// 	url: item.appJumpPath
					// 		// };
					// 		// this.$bridge.callHandler('recruitHandler', data1, () => {
					// 		// 	console.log('recruitHandler', '返回');
					// 		// });
					// 	} else if (item.appJumpPath == 'EnterpriseCardDetail') {
					// 		const data1 = {
					// 			type: 'companyCard',
					// 			companyId: JSON.parse(item.appJumpParam).companyId
					// 		};
					// 		this.$bridge.callHandler('recruitHandler', data1, () => {
					// 			console.log('recruitHandler', '返回');
					// 		});
					// 	}
					// } else {
					// 	this.$bridge.callHandler('recruitHandler', data, () => {
					// 		console.log('recruitHandler', '返回');
					// 	});
					// }
				} else {
					this.$pageTo('/about/guidePage');
				}
				// }
			} else {
				this.$refs.notLogin.openLogin({
					show: true,
					position: 'center'
				});
			}
		},
		goPage(e) {
			const { bw_params } = getApp().getBWData(['bw_params']);
			if (bw_params && bw_params.access_token) {
				if (e == 'user') {
					console.log('this.isChange',this.isChange)
					if(this.isChange){
						uni.navigateBack()
					}else{
						this.$pageTo('/recruit/user/home?isChange=1');
					}
				} else if (e == 'search') {
					this.$pageTo('/recruit/user/searchList');
				} else if (e == 'filter') {
					getApp().globalData.filterTemp = {};
					this.$pageTo('/recruit/common/filter?type=job');
				} else if (e.appJumpPath) {
					// window.open(e.appJumpPath)
					// window.location.href=e.appJumpPath;
					const op = location.origin + location.pathname + '#'; // 'http://ebc-test.benwunet.com/h5/#'
					const url = e.appJumpPath.replace(op, '');
					this.$pageTo(url);
				} else {
					// this.$pageTo(e.appJumpPath)
					console.log(e);
				}
			} else {
				this.login();
			}
		},
		login() {
			this.$refs.notLogin.openLogin({
				show: true,
				position: 'center'
			});
		}
	}
};
</script>

<style lang="scss" scoped>
.changePage {
	display: flex;
	justify-content: center;
	width: 100%;
	height: 130rpx;
	position: fixed;
	bottom: 0rpx;
	.bottomDetail {
		height: 88rpx;
		width: 670rpx;
		border-radius: 12rpx;
		background: #ffffff;
		box-shadow: 0 4rpx 10rpx rgba(0,0,0,.2);
		overflow: hidden;
		.bwfont {
			margin-right: 10rpx;
			font-size: 34rpx;
		}
		.btn {
			color: var(--titleFontColor);
		}
		.active{
			color: var(--contentBgImageTitleColor);
		}
	}
}
.search-box {
	padding: 0 24rpx;
}
.search-box .input {
	padding: 0 24rpx;
}
.set-btn {
	background-color: rgba(255, 217, 181, 0.1);
	width: 64rpx;
	height: 64rpx;
	border-radius: 50%;
}
.color-747986 {
	color: var(--contentFontDarkColor);
}
.bg-232732 {
	background-color: var(--searchViewBackColor);
	height: 64rpx;
	border-radius: 32rpx;
}
.banner{padding: 0 24rpx;}
.swiper-banner {
	margin-top: 42rpx;
	// width: 702rpx;
	width: 100%;
	height: 236rpx;
	border-radius: 12rpx;
}

.swiper-banner .pic {
	width: 100%;
	height: 236rpx;
	border-radius: 12rpx;
}
@media (min-width: 780px) {
	
	.swiper-banner {
		height: 472rpx;
	}

	.swiper-banner .pic {
		height: 472rpx;
	}
}
.list {
	padding: 24rpx 24rpx 24rpx;
}

</style>
